package routers

import (
	"github.com/gin-gonic/gin"
	"hass.tree.com/bridge/auth"
	"hass.tree.com/bridge/kafka"
	"hass.tree.com/bridge/vo"
)

func LoadKafka(e *gin.Engine) {
	kafkaRoute := e.Group("/kafka")
	{
		kafkaRoute.Use(auth.JWTauth())
		kafkaRoute.POST("/send", sendMessage)
	}

}
func sendMessage(c *gin.Context) {
	var kafakMessage vo.KafkaMessage
	if err := c.ShouldBindJSON(&kafakMessage); err != nil {
		vo.Fail(err.Error(), c)
		return
	}

	kafka.SendMessage(kafakMessage.Topic, kafakMessage.Message)
	vo.SuccessE(c)
}
